package com.nodecollege.cloud.service.impl.deal;

import com.alibaba.fastjson.JSON;
import com.nodecollege.cloud.common.model.NCResult;
import com.nodecollege.cloud.common.model.po.ChatGroupUser;
import com.nodecollege.cloud.common.model.vo.ChatGroupData;
import com.nodecollege.cloud.common.utils.ThreadUserUtils;
import com.nodecollege.cloud.service.ChatService;
import com.nodecollege.cloud.service.GroupUserService;
import com.nodecollege.cloud.service.impl.ChatServiceAbstrat;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 获取群组用户信息
 *
 * @author LC
 * @date 2020/2/26 23:07
 */
@Slf4j
@Service
public class ChatGroupUserServiceImpl extends ChatServiceAbstrat implements ChatService {

    @Autowired
    private GroupUserService groupUserService;

    /**
     * 获取群组用户信息
     *
     * @param chatData
     * @param channel
     */
    @Override
    public void handler(String chatData, Channel channel) {
        log.info("ChatHandlerKeepLiveServiceImpl handler");
        ChatGroupData groupData = JSON.parseObject(chatData, ChatGroupData.class);
        List<ChatGroupUser> userList = groupUserService.getGroupUser(groupData.getGroupId());
        // 给自己发送
        sendMsg(ThreadUserUtils.getLoginUser().getUserId(), NCResult.ok(userList), 4);
    }
}
